package dao;

import domain.Car;
import util.DbUtil;

import java.sql.ResultSet;
import java.sql.SQLException;

public class CarDao {

    DbUtil db = new DbUtil();
    public int pageSize = 10;

    public Car findCarMsgById(int id){
        String sql = "select * from car where id="+id+" ";
        ResultSet rs = db.executeQuery(sql);
        try {
            if(rs.next()){
                return converToCar(rs);
            }else {
                return null;
            }
        }catch (SQLException e){
            e.printStackTrace();
            return null;
        }
    }















    public Car converToCar(ResultSet rs)  {
        Car car = null;
        try {
            int id = rs.getInt(1);
            String userid = rs.getString(2);
            String goodspic = rs.getString(3);
            String goodsprice = rs.getString(4);
            int num = rs.getInt(5);
            car = new Car(id, userid, goodspic, goodsprice, num);
            return car;
        }catch (SQLException e){
            e.printStackTrace();
            return null;
        }
    }
}
